﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.WpfClient.Views.Master;

using System.IO;
using System.Windows.Xps.Packaging;
using System.Windows.Xps;
using System.Windows.Documents;
using Microsoft.Practices.Unity;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Markup;
using System.Xml;
using System.Windows.Annotations;


namespace Skynet.C2SModule.Presenters
{
    public class BookPrintPresenter : MasterPresenter<Views.BookPrint.IBookPrintView>
    {
        //[Dependency]
        //public BusinessLogic.BusinessComponents.IBCBooks BCBooks { get; set; }

        public BookPrintPresenter(IUnityContainer container)
            : base( container)
        {
        }

        public FixedDocumentSequence Document { get; set; }
        
        public ICollectionView Books { get; set; }

        public override void OnViewReady()
        {

            //Books = CollectionViewSource.GetDefaultView(BCBooks.GetAll().ToList());
            //Books.CurrentChanged += new EventHandler(Books_CurrentChanged);            
            //this.InvokePropertyChanged("Books");

            ////var doc = new XpsDocument(@"C:\Prueba documento fijo.xps", System.IO.FileAccess.Read);
            ////Document = doc.GetFixedDocumentSequence();
            ////doc.Close();

            this.InvokePropertyChanged("Document");
        }
        
        void Books_CurrentChanged(object sender, EventArgs e)
        {

            //try
            //{
            //    var currentbook = this.Books.CurrentItem as BusinessLogic.BusinessEntities.Book;

                
                

            //    var doc = new XpsDocument(Path.GetTempFileName() + ".xps", FileAccess.ReadWrite);
            //    XpsDocumentWriter writter = XpsDocument.CreateXpsDocumentWriter(doc);

            //    System.IO.TextReader textreader = new System.IO.StringReader(currentbook.Content);
            //    var reader = XmlReader.Create(textreader);
            //    var flowDocument = (FlowDocument)XamlReader.Load(reader);
            //    writter.Write((flowDocument as IDocumentPaginatorSource).DocumentPaginator);
            //    Document = doc.GetFixedDocumentSequence();
            //    doc.Close();
            //    this.InvokePropertyChanged("Document");
            //}
            //catch (Exception)
            //{
                
                
            //}
            
        }
    }
}
